<script>
	export default {
		onLaunch: function(option) {
			// uni.removeStorageSync('channelCode')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			isRealName: false, //判定是否实名
			hasLogin: false, //判定是否登录
			phone: '',
			homePage:'/pages/index/index',//首页
			tabBarList:[
				'/pages/index/index',
				'/pages/merchant/merchant',
				'/pages/order/order',
				'/pages/my/my',
			], //底部导航页面列表
		},
		methods: {
			//判断是否在微信中
			isWechat: function() {
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/micromessenger/i) == 'micromessenger') {
					//console.log('是微信客户端')  
					return true;
				} else {
					//console.log('不是微信客户端')  
					return false;
				}
			},
			// 检查是否登录
			checkLogin() {
				if (uni.getStorageSync('token') != undefined && uni.getStorageSync('token') != '') {
					return true
				} else {
					return false
				}
			},
			// 判定当前用户机型 引用不同跳转方式
			determineModel(url) {
				uni.navigateTo({
					url
				})	
			},
			getLogin(type) { //微信授权登录
				var local = window.location.href //获取页面当前路径
				local = local.split('?')[0]
				var linkJump = this.getUrlParam('linkJump')
				var linkCode = this.getUrlParam('linkCode')
				if(linkJump != null && linkJump !== '' && type == 1){
					local = local + '?linkJump=' + linkJump + '&linkCode=true'
				}
				else if (linkJump != null && linkJump !== '') {
					local = local + '?linkJump=' + linkJump
				}
				else if(type == 1){
					local = local + '?linkCode=true'
				}
				
				// console.log(local)
				let appid = this.appId
				let redirect_uri = encodeURIComponent(local)
				let response_type = 'code'
				let scope = "snsapi_base"
				let state = "STATE#wechat_redirect"
				// console.log(redirect_uri)
				// console.log(local)
				if (type == 1) {
					scope = "snsapi_userinfo"
				}
				location.href =
					"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + '&redirect_uri=' +
					redirect_uri + '&response_type=' + response_type + '&scope=' + scope + '&state=' + state

				// location.href =`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=${response_type}&scope=${scope}&state=${state}`
					
			},
			getUrlParam(name) {
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
				var r = window.location.search.substr(1).match(reg)
				if (r != null) return unescape(r[2])
				return null
			},
			async validate_realName_login() {
				var data = {
					realName: false,
					login: false
				}
				if (uni.getStorageSync('token') != undefined) {
					data.login = true
					var res = await this.$api.getRealNameInfo()
					if (res.data.idCard == '' || res.data.name == '') {
						data.realName = false
					} else {
						data.realName = true
					}
				}
				return data
			},
			// 公共跳转 登录后配置跳转链接
			// type 跳转类型 1 navigateTo 2 redirectTo 3 reLaunch
			// showTip 是否显示提示
			jumpPublicLogin(type = 1, showTip = false) {
				var curRoute = this.getParam()
				if (showTip) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						this.jumpUrl(type, curRoute)
					}, 1000)
				} else {
					this.jumpUrl(type, curRoute)
				}
				// console.log(curRoute)
			},
			// 公共跳转 实名后配置跳转链接 
			// type 跳转类型 1 navigateTo 2 redirectTo 3 reLaunch 
			// showTip 是否显示提示
			jumpPublicRealName(type = 1, showTip = false) {
				var curRoute = this.getParam()
				if (showTip) {
					uni.showToast({
						title: '请实名',
						icon: 'none'
					})
					setTimeout(() => {
						this.jumpUrl(type, curRoute, false)
					}, 1000)
				} else {
					this.jumpUrl(type, curRoute, false)
				}
				// console.log(curRoute)
			},
			// type 跳转类型 1 navigateTo 2 redirectTo 3 reLaunch
			// curRoute 跳转链接
			// isLogin 是否跳转到登录页面
			jumpUrl(type, curRoute, isLogin = true) {
				var url = ''
				if (isLogin) {
					url = "/pages/login/login?linkJump=true"
					uni.setStorageSync('linkJump', encodeURIComponent(JSON.stringify(curRoute)));
				} else {
					url = "/pages/subPackages/pagesC/certification/certification?linkJump=" + encodeURIComponent(JSON.stringify(curRoute))
				}
				if (type == 1) {
					uni.navigateTo({
						url: url
					})
				} else if (type == 2) {
					uni.redirectTo({
						url: url
					})
				} else if (type == 3) {
					uni.reLaunch({
						url: url
					})
				}
			},
			// 获取当前url 地址
			getParam() {
				var routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				var curRoute = routes[routes.length - 1].route //获取当前页面路由
				var curParam = routes[routes.length - 1].options; //获取路由参数
				// 拼接参数
				var param = ''
				// console.log(curParam)
				var i = 0
				for (var key in curParam) {
					if (i == 0) {
						param += '?' + key + '=' + curParam[key]
					} else {
						param += '&' + key + '=' + curParam[key]
					}
					i++
		
				}
				var pageUrl = '/' + curRoute + param
				return pageUrl
			},
			// 判断值是否为空
			isEmpty(obj) {
				try {
					if (obj == null || obj == undefined) {
						return true;
					}
					//判断数字是否是NaN
					if (typeof obj === "number") {
						if (isNaN(obj)) {
							return true;
						} else {
							return false;
						}
					}
					//判断参数是否是布尔、函数、日期、正则，是则返回false
					if (typeof obj === "boolean" || typeof obj === "function" || obj instanceof Date ||
						obj instanceof RegExp) {
						return false;
					}
					//判断参数是否是字符串，去空，如果长度为0则返回true
					if (typeof obj === "string") {
						if (obj.trim().length == 0) {
							return true;
						} else {
							return false;
						}
					}
		
					if (typeof obj === 'object') {
						//判断参数是否是数组，数组为空则返回true
						if (obj instanceof Array) {
							if (obj.length == 0) {
								return true;
							} else {
								return false;
							}
						}
		
						//判断参数是否是对象，判断是否是空对象，是则返回true
						if (obj instanceof Object) {
							//判断对象属性个数
							if (Object.getOwnPropertyNames(obj).length == 0) {
								return true;
							} else {
								return false;
							}
						}
					}
				} catch (e) {
					console.log(e);
					return false;
				}
			},
		
		},
	}
</script>

<style>
	/*每个页面公共css */
	/* 一行溢出 */
	.ellipseHide {
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	/* 两行行溢出 */
	.ellipseHide_two {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	/* 公共底部loding加载 */
	.bottomLoading {
		padding-top: 20rpx;
		padding-bottom: 100rpx;
		width: 100%;
		text-align: center;
		color: #999999;
		font-size: 28rpx;
	}

	.button:active {
		opacity: 0.8;
	}

	.no_info {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 448rpx;
	}

	/* 去除scroll滚动条 */
	::-webkit-scrollbar {
		display: none;
		width: 0;
		height: 0;
		background-color: transparent;
	}

	.no_info text {
		color: #999999;
		font-size: 28rpx;
	}

	.no_info image {
		width: 480rpx;
		height: 268rpx;
		margin-bottom: 18rpx;
	}

	.unsetBo {
		border: unset;
	}

	.imgBox {
		width: 100%;
		height: 100%;
	}

	view {
		word-break: break-all;
	}

	uni-rich-text {
		word-break: break-all;
	}

	uni-rich-text img {
		max-width: 100% !important;
		height: auto !important;
	}

	uni-rich-text p {
		max-width: 100%;
		word-break: break-all;
	}

	uni-tabbar,
	uni-tabbar .uni-tabbar {
		/* box-shadow: 0rpx -10rpx 8rpx #F3F3F3; */
	}
</style>